/**
 * Created by yindu on 2018/12/17.
 */
var express = require('express');
var router = express.Router();
var db = require('../libs/mysql');
//统一返回格式
var res_Data;
router.use( function(req, res, next) {
    res_Data = {
        code: 0,
        message: ''
    }
    next();
});

router.post('/',function (req,res) {
    var data = req.body.addContent;
    var title = data.title,
        author = data.author,
        start_time = data.start_time,
        end_time = data.end_time;

    db.query(`INSERT INTO home ( title,author,start_time,end_time) VALUES ('${title}','${author}','${start_time}','${end_time}');`,(err)=>{
        if(err){
            res.send('增加课程').end();
        }else {
            res_Data.message = '添加成功';
            res.json(res_Data);
            return;
        }
    })
})
module.exports = router;